package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.healthyeating.manage.domain.vo.ShareVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.Share;
import com.healthyeating.manage.service.IShareService;
import com.healthyeating.common.utils.poi.ExcelUtil;
import com.healthyeating.common.core.page.TableDataInfo;

/**
 * 发现分享Controller
 *
 * @author 段奇乐
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/manage/share")
public class ShareController extends BaseController {

    @Autowired
    private IShareService shareService;

    /**
     * 查询发现分享列表
     */
    @PreAuthorize("@ss.hasPermi('manage:share:list')")
    @GetMapping("/list")
    public TableDataInfo list(Share share) {
        startPage();
        List<ShareVo> list = shareService.selectShareList(share);
        return getDataTable(list);
    }

    /**
     * 获取发现分享详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:share:query')")
    @GetMapping(value = "/{shareId}")
    public AjaxResult getInfo(@PathVariable("shareId") Long shareId) {
        return success(shareService.selectShareByShareId(shareId));
    }

    /**
     * 新增发现分享
     */
    @PreAuthorize("@ss.hasPermi('manage:share:add')")
    @Log(title = "发现分享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Share share, HttpServletRequest request) {
        return toAjax(shareService.insertShare(share, request));
    }

    /**
     * 修改发现分享
     */
    @PreAuthorize("@ss.hasPermi('manage:share:edit')")
    @Log(title = "发现分享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShareVo shareVo) {
        return toAjax(shareService.updateShare(shareVo));
    }

    /**
     * 删除发现分享
     */
    @PreAuthorize("@ss.hasPermi('manage:share:remove')")
    @Log(title = "发现分享", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shareIds}")
    public AjaxResult remove(@PathVariable Long[] shareIds) {
        return toAjax(shareService.deleteShareByShareIds(shareIds));
    }
}
